//
//  AuthenPendingTypeVM.swift
//  kxf
//  商户待处理 状态
//  Created by Mac on 2024/3/10.
//

import Foundation
import UIKit

enum AUTHEN_PENDGING_STATUS {
    case status_ruwang_ing
    case status_check_ing
    case status_authori_ing
    case status_refuse
}

class AuthenPendingTypeVM: UIView {
    
    let selfHeight = kFitWidth(44)
    
    var type = AUTHEN_PENDGING_STATUS.status_ruwang_ing
    var typeChangeBlock:((AUTHEN_PENDGING_STATUS)->())?

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: frame.origin.y, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var firstVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "入网中"
        vm.setSelected(isSelect: true)
        vm.tapBlock = {()in
            if self.type != .status_ruwang_ing{
                self.type = .status_ruwang_ing
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var secondVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.25, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "审核中"
        vm.tapBlock = {()in
            if self.type != .status_check_ing{
                self.type = .status_check_ing
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var thirdVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.5, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "待授权"
        vm.tapBlock = {()in
            if self.type != .status_authori_ing{
                self.type = .status_authori_ing
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
    lazy var fourthVm : AUthenTopTypeButton = {
        let vm = AUthenTopTypeButton.init(frame: CGRect.init(x: SCREEN_WIDHT*0.75, y: 0, width: SCREEN_WIDHT*0.25, height: kFitWidth(44)))
        vm.titleLabel.text = "已拒绝"
        vm.tapBlock = {()in
            if self.type != .status_refuse{
                self.type = .status_refuse
                self.typeChangeAction()
                self.setBtnNormal()
            }
        }
        return vm
    }()
}

extension AuthenPendingTypeVM{
    @objc func typeChangeAction() {
        if self.typeChangeBlock != nil{
            self.typeChangeBlock!(self.type)
        }
    }
    func setBtnNormal() {
        self.firstVm.setSelected(isSelect: self.type == .status_ruwang_ing ? true : false)
        self.secondVm.setSelected(isSelect: self.type == .status_check_ing ? true : false)
        self.thirdVm.setSelected(isSelect: self.type == .status_authori_ing ? true : false)
        self.fourthVm.setSelected(isSelect: self.type == .status_refuse ? true : false)
    }
}
extension AuthenPendingTypeVM{
    func initUI() {
        addSubview(firstVm)
        addSubview(secondVm)
        addSubview(thirdVm)
        addSubview(fourthVm)
    }
}

